/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2015-2018. All rights reserved.
 * Description: Signature Verify CBB Library
 * Author: tangzonglei
 * Create: 2015
 * History: 2018/11/23 yebin code rule fixes
 */
#include "../asn1/cmscbb_asn1_def.h"

#define CVB_AOID_UNKNOWN                 "\377"
/* PKCS1 suite */
#define CVB_AOID_RSA                     "\52\206\110\206\367\15\1\1\1"
#define CVB_AOID_RSASSAPSS               "\52\206\110\206\367\15\1\1\12"
#define CVB_AOID_SHA256WITHRSAENCRYPTION "\52\206\110\206\367\15\1\1\13"
#if CMSCBB_SUPPORT_SHA384
#define CVB_AOID_SHA384WITHRSAENCRYPTION "\52\206\110\206\367\15\1\1\14"
#endif
#if CMSCBB_SUPPORT_SHA512
#define CVB_AOID_SHA512WITHRSAENCRYPTION "\52\206\110\206\367\15\1\1\15"
#endif

/* digest algorithm */
#define CVB_AOID_SHA256 "\140\206\110\1\145\3\4\2\1"
#if CMSCBB_SUPPORT_SHA384
#define CVB_AOID_SHA384 "\140\206\110\1\145\3\4\2\2"
#endif
#if CMSCBB_SUPPORT_SHA512
#define CVB_AOID_SHA512 "\140\206\110\1\145\3\4\2\3"
#endif

/* PKCS7 suite */
#define CVB_AOID_PKCS7_SIGNEDDATA "\52\206\110\206\367\15\1\7\2"
#define CVB_AOID_PKCS7_TSTINFO "\52\206\110\206\367\15\1\11\20\1\4"

/* PKIX IMPLICIT */
#define CVB_AOID_CE_KEYUSAGE                 "\125\35\17"
#define CVB_AOID_CE_BASICCONSTRAINTS         "\125\35\23"
#define CVB_AOID_CE_CRLREASONS               "\125\35\25"
#if     CMSCBB_SUPPORT_INDIRECT_CRL
#define CVB_AOID_CE_ISSUINGDISTRIBUTIONPOINT "\125\35\34"
#define CVB_AOID_CE_CRLNUMBER                "\125\35\24"
#endif
#define CVB_AOID_CE_EXTKEYUSAGE              "\125\35\45"
#define CVB_AOID_KP_CODESIGNING              "\53\6\1\5\5\7\3\3"
#define CVB_AOID_KP_TIMESTAMPING             "\53\6\1\5\5\7\3\10"

/* ATTRIBUTE suite */
#define CVB_AOID_AT_COMMONNAME               "\125\4\3"
#define CVB_AOID_AT_LOCALITYNAME             "\125\4\7"
#define CVB_AOID_AT_STATEORPROVINCENAME      "\125\4\10"
#define CVB_AOID_AT_ORGANIZATIONNAME         "\125\4\12"
#define CVB_AOID_AT_ORGANIZATIONALUNITNAME   "\125\4\13"
#define CVB_AOID_AT_COUNTRYNAME              "\125\4\6"

/* PKCS9 suite */
#define CVB_AOID_PKCS9_AT_MESSAGEDIGEST      "\52\206\110\206\367\15\1\11\4"
#define CVB_AODI_PKCS9_AT_CONTENTTYPE        "\52\206\110\206\367\15\1\11\3"
#define CVB_AOID_PKCS9_AT_TIMESTAMP_TOKEN    "\52\206\110\206\367\15\1\11\20\2\16"
#define CVB_AOID_PKCS9_AT_EMAILADDRESS       "\52\206\110\206\367\15\1\11\1"

/* Huawei customized OID */
#define CVB_AOID_CT_ANIMAJSONVOUCHER         "\52\206\110\206\367\15\1\11\20\1\50" // 1.2.840.113549.1.9.16.1.40
#define CVB_AOID_HW_KP_VOUCHERSIGNING        "\53\6\1\4\1\217\133\201\111\1\3\2" // 1.3.6.1.4.1.2011.201.1.3.2
#define CVB_AOID_HW_KP_RELEASESIGNING        "\53\6\1\4\1\217\133\201\111\1\3\1" // 1.3.6.1.4.1.2011.201.1.3.1

/* ANSI X9.62 */
#define CVB_AOID_ECDSA "\52\206\110\316\75"
#define CVB_AOID_SHA256WITHECDSA "\52\206\110\316\75\04\03\02"
#define CVB_AOID_NIST_CURVE_P256 "\52\206\110\316\75\03\01\07"
#define CVB_AOID_BRAINPOOL_CURVE_P256 "\53\44\03\03\02\10\01\01\07"
#if CMSCBB_SUPPORT_SHA384
#define CVB_AOID_SHA384WITHECDSA "\52\206\110\316\75\04\03\03"
#define CVB_AOID_NIST_CURVE_P384 "\53\201\04\00\42"
#define CVB_AOID_BRAINPOOL_CURVE_P384 "\53\44\03\03\02\10\01\01\13"
#endif
#if CMSCBB_SUPPORT_SHA512
#define CVB_AOID_SHA512WITHECDSA "\52\206\110\316\75\04\03\04"
#define CVB_AOID_NIST_CURVE_P512 "\53\201\04\00\43"
#define CVB_AOID_BRAINPOOL_CURVE_P512 "\53\44\03\03\02\10\01\01\15"
#endif

#define CVB_OID_DEF(aoid)                           \
    {                                               \
        aoid,                                       \
        { (CVB_UINT32)(sizeof(CVB_##aoid) - 1),     \
          { CBC_UNIV, CBF_PRIM, CBT_OID },          \
          (const CVB_BYTE*)(CVB_##aoid)             \
        },                                          \
        (const CVB_CHAR*)(#aoid)                    \
    }

static CmscbbOidInfo g_cvbOIDTable[] = {
    CVB_OID_DEF(AOID_UNKNOWN),
    CVB_OID_DEF(AOID_SHA256),
#if CMSCBB_SUPPORT_SHA384
    CVB_OID_DEF(AOID_SHA384),
#endif
#if CMSCBB_SUPPORT_SHA512
    CVB_OID_DEF(AOID_SHA512),
#endif
    CVB_OID_DEF(AOID_RSA),
    CVB_OID_DEF(AOID_RSASSAPSS),
    CVB_OID_DEF(AOID_SHA256WITHRSAENCRYPTION),
#if CMSCBB_SUPPORT_SHA384
    CVB_OID_DEF(AOID_SHA384WITHRSAENCRYPTION),
#endif
#if CMSCBB_SUPPORT_SHA512
    CVB_OID_DEF(AOID_SHA512WITHRSAENCRYPTION),
#endif
    CVB_OID_DEF(AOID_AT_COMMONNAME),
    CVB_OID_DEF(AOID_AT_LOCALITYNAME),
    CVB_OID_DEF(AOID_AT_STATEORPROVINCENAME),
    CVB_OID_DEF(AOID_AT_ORGANIZATIONNAME),
    CVB_OID_DEF(AOID_AT_ORGANIZATIONALUNITNAME),
    CVB_OID_DEF(AOID_AT_COUNTRYNAME),
    CVB_OID_DEF(AOID_PKCS9_AT_EMAILADDRESS),
    CVB_OID_DEF(AOID_CE_KEYUSAGE),
    CVB_OID_DEF(AOID_CE_BASICCONSTRAINTS),
    CVB_OID_DEF(AOID_CE_EXTKEYUSAGE),
    CVB_OID_DEF(AOID_KP_CODESIGNING),
    CVB_OID_DEF(AOID_KP_TIMESTAMPING),
#if CMSCBB_SUPPORT_INDIRECT_CRL
    CVB_OID_DEF(AOID_CE_ISSUINGDISTRIBUTIONPOINT),
    CVB_OID_DEF(AOID_CE_CRLNUMBER),
#endif
    CVB_OID_DEF(AOID_CE_CRLREASONS),
    CVB_OID_DEF(AOID_PKCS7_SIGNEDDATA),
    CVB_OID_DEF(AOID_PKCS7_TSTINFO),
    CVB_OID_DEF(AOID_CT_ANIMAJSONVOUCHER),
    CVB_OID_DEF(AOID_PKCS9_AT_MESSAGEDIGEST),
    CVB_OID_DEF(AODI_PKCS9_AT_CONTENTTYPE),
    CVB_OID_DEF(AOID_PKCS9_AT_TIMESTAMP_TOKEN),
    CVB_OID_DEF(AOID_HW_KP_VOUCHERSIGNING),
    CVB_OID_DEF(AOID_HW_KP_RELEASESIGNING),
    CVB_OID_DEF(AOID_ECDSA),
    CVB_OID_DEF(AOID_SHA256WITHECDSA),
#if CMSCBB_SUPPORT_SHA384
    CVB_OID_DEF(AOID_SHA384WITHECDSA),
#endif
#if CMSCBB_SUPPORT_SHA512
    CVB_OID_DEF(AOID_SHA512WITHECDSA),
#endif
    CVB_OID_DEF(AOID_NIST_CURVE_P256),
    CVB_OID_DEF(AOID_BRAINPOOL_CURVE_P256),
#if CMSCBB_SUPPORT_SHA384
    CVB_OID_DEF(AOID_NIST_CURVE_P384),
    CVB_OID_DEF(AOID_BRAINPOOL_CURVE_P384),
#endif
#if CMSCBB_SUPPORT_SHA512
    CVB_OID_DEF(AOID_NIST_CURVE_P512),
    CVB_OID_DEF(AOID_BRAINPOOL_CURVE_P512),
#endif
};

#if CMSCBB_NEED_RELOCATE
CVB_BOOL g_cvbOidReloced = CVB_FALSE;
CVB_BOOL GetCvbOidReloced(void)
{
    return g_cvbOidReloced;
}
CVB_VOID SetCvbOidReloced(CVB_BOOL isReloced)
{
    g_cvbOidReloced = isReloced;
    return;
}
#endif

CmscbbOidInfo* GetCvbOIDTable(void)
{
    return g_cvbOIDTable;
}

CVB_UINT32 GetCvbOidCount(void)
{
    return sizeof(g_cvbOIDTable) / sizeof(CmscbbOidInfo);
}
